/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package heitor.hosts.bean;

import heitor.cp.lazy.LazyCPDataModel;
import heitor.hosts.servicos.ContasPagar;
import heitor.hosts.servicos.DAOJPAContasPagar;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;

/**
 *
 * @author heitorsantos
 */
@ManagedBean(name="aprovaBean")
///@ViewScoped
public class AprovaBean implements Serializable {
     
    private LazyDataModel<ContasPagar> lazyModel;
     
    private ContasPagar selectedCar;
    
    ///HEITOR
    private DAOJPAContasPagar dao = new DAOJPAContasPagar();
     
    ///@ManagedProperty("#{carService}")
    ///private CarService service;
     
    @PostConstruct
    public void init() {
        lazyModel = new LazyCPDataModel(dao.getByEmissao("20140801"));///service.createCars(200));
    }
 
    public LazyDataModel<ContasPagar> getLazyModel() {
        return lazyModel;
    }
 
    public ContasPagar getSelectedCar() {
        return selectedCar;
    }
 
    public void setSelectedCar(ContasPagar selectedCar) {
        this.selectedCar = selectedCar;
    }
     
    ///public void setService(CarService service) {
    ///    this.service = service;
    ///}
     
    public void onRowSelect(SelectEvent event) {
        
        FacesMessage msg = new FacesMessage("Car Selected", ((ContasPagar) event.getObject()).getRECNO().toString());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}